<?
include('header.php');

if(!$is_online){
	redirect('index.php');
	exit;
}


$sql = $db->Query("SELECT id,site,title,cpc FROM `linkedin` WHERE (`active` = '0' AND `points` >= `cpc`) AND (`id` NOT IN (SELECT `site_id` FROM `linked` WHERE `user_id`='".$data['id']."') AND `user`!='".$data['id']."') ORDER BY `cpc` DESC LIMIT 7");
$ext = $db->GetNumRows($sql);
$sites = $db->FetchArrayAll($sql);
?>
<div class="block medium right">
			<div class="top">
                  <h1>Earn Coins - Linkedin</h1>
            </div>
			<div class="content">	
<?
if($ext > 0){
?>
<p>Press "Share" on this page and after that press "Share" on Linkedin's page.</p>
<script type="text/javascript">
	
function removeElement(parentDiv, childDiv){
     if (document.getElementById(childDiv)) {     
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
          parent.removeChild(child);
     }
}


function refreshpage()
{
  window.location.reload();
}

function getQueryParams(qs) {
    qs = qs.split("+").join(" ");
    var params = {}, tokens,
        re = /[?&]?([^=]+)=([^&]*)/g;
    while (tokens = re.exec(qs)) {
        params[decodeURIComponent(tokens[1])]
            = decodeURIComponent(tokens[2]);
    }
    return params;
}

function click_callback(id){
removeElement('getpoints', id);
var user = "<?=$data['id'];?>";
$("#txtHint").html('<table cellpadding="2" cellspacing="0" width="500" align="center" class="maintable"><tr><td align="center"><font size="3"><b>Verifying Share... <img src="img/ajax-loader.gif"></b></font></td></tr><tr><td><center><font size=2><b>Share was Successful!</b></font></center></td></tr></table><br>');
$.ajax({
type: "POST",
url: "linked.php",
data: "id="+ id + "&user=" + user,
success: function(msg){
   document.getElementById("Hint").style.display='block';
   $("#txtHint").html('<table cellpadding="2" cellspacing="0" width="500" align="center" class="maintable"><tr><td align="center"><font size="3"><b>Verifying Share... </b></font></td></tr><tr><td><center><font size=2><b>Share was Successful!</b></font></center></td></tr></table><br>');
   
	}
});
}
</script>
<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
<center><div id="txtHint" style="display:block;"></div></center>
<div id="getpoints">
<?
  foreach($sites as $site){
?>
<div class="follow" id="<?=$site['id']?>">
 
 
        <script type="IN/Share" data-url="<?=$site['site']?>" data-counter="right" data-onSuccess="shared<?=$site['id']?>"></script>
	<div class="title"><a href="<?=$site['site']?>" target="_blank" style="color:blue;"><?=$site['title']?></a></div>
	<div class="points">Coins: <b><?=$site['cpc']?></b></div>

  
 
    
    
</div>
<script type="text/javascript">
function shared<?=$site['id']?>(){
click_callback('<?=$site['id']?>');	
}
</script>


	

<?}?>
</div>
<br>
<div class='infobox'><form action='' method='' onsubmit='refreshpage();'><input name='refresh' type='submit' value='Refresh'></form></div>
<?}else{?>
<div class="msg">
<div class="error">Sorry, there are no more coins to be earned at the moment. Please try again later.</div>
<div class="info"><a href="buy.php"><b>Need more coins? You can buy more here!</b></a></div></div>
<?}?>
				</div>
			</div>		
<?include('footer.php');?>